﻿namespace Devonline.Core
{
    /// <summary>
    /// 默认的基础配置
    /// </summary>
    public class AppSetting
    {
        /// <summary>
        /// 启动站点配置
        /// </summary>
        public string Hosts { get; set; }
        /// <summary>
        /// 允许访问的地址
        /// </summary>
        public string AllowedHosts { get; set; }
        /// <summary>
        /// 跨域配置
        /// </summary>
        public string CorsOrigins { get; set; }
        /// <summary>
        /// 默认身份数据库连接字符串
        /// </summary>
        public string IdentityDbContext { get; set; }
        /// <summary>
        /// 默认应用数据库连接字符串
        /// </summary>
        public string ApplicationDbContext { get; set; }
        /// <summary>
        /// 默认密码
        /// </summary>
        public string DefaultPassword { get; set; }
        /// <summary>
        /// 数据保护级别
        /// </summary>
        public DataProtectionLevel ProtectionLevel { get; set; }

        /// <summary>
        /// identity options
        /// </summary>
        public IdentityOptions Identity { get; set; }
        /// <summary>
        /// https certificate configuration
        /// </summary>
        public HttpsCertificate Certificate { get; set; }
        /// <summary>
        /// 附件相关配置项
        /// </summary>
        public AttachmentOptions Attachment { get; set; }
    }

    public class IdentityOptions
    {
        public IdentityOptions()
        {
            Authority = "https://localhost:9527";
            SaveTokens = true;
        }

        /// <summary>
        /// 认证服务地址
        /// </summary>
        public string Authority { get; set; }
        /// <summary>
        /// 客户端编号
        /// </summary>
        public string ClientId { get; set; }
        /// <summary>
        /// 客户端密钥
        /// </summary>
        public string ClientSecret { get; set; }
        /// <summary>
        /// 返回值类型
        /// </summary>
        public string ResponseType { get; set; }
        /// <summary>
        /// Defines whether access and refresh tokens should be stored in the Microsoft.AspNetCore.Authentication.AuthenticationProperties
        ///     after a successful authorization. This property is set to false by default to
        ///     reduce the size of the final authentication cookie.
        /// </summary>
        public bool SaveTokens { get; set; }
    }

    /// <summary>
    /// https certificate configuration
    /// </summary>
    public class HttpsCertificate
    {
        /// <summary>
        /// 域名
        /// </summary>
        public string Domain { get; set; }
        /// <summary>
        /// 证书地址
        /// </summary>
        public string Path { get; set; }
        /// <summary>
        /// 证书密码
        /// </summary>
        public string Password { get; set; }
    }

    /// <summary>
    /// 附件相关选项
    /// </summary>
    public class AttachmentOptions
    {
        /// <summary>
        /// 构造方法
        /// </summary>
        public AttachmentOptions()
        {
            EnableUpload = true;
            RootPath = AppSettings.DEFAULT_ATTACHMENT_PATH;
            AllowFileExtensions = AppSettings.DEFAULT_ALLOW_FILE_EXTENSIONS;
            TempFileExtension = AppSettings.DEFAULT_TEMPORARY_FILE_EXTENSION;
            MaxUploadFileSize = AppSettings.DEFAULT_MAX_UPLOAD_FILE_SIZE;
            TotalUploadFileSize = AppSettings.DEFAULT_TOTAL_UPLOAD_FILE_SIZE;
            ImageThumbnailPrefix = AppSettings.DEFAULT_IMAGE_THUMBNAIL_PREFIX;
            ImageThumbnailSize = AppSettings.DEFAULT_IMAGE_THUMBNAIL_SIZE;
        }

        public bool EnableUpload { get; set; }
        /// <summary>
        /// 附件根路径
        /// </summary>
        public string RootPath { get; set; }
        /// <summary>
        /// 允许上传的附件类型
        /// </summary>
        public string AllowFileExtensions { get; set; }
        /// <summary>
        /// 临时文件扩展名
        /// </summary>
        public string TempFileExtension { get; set; }
        /// <summary>
        /// 单附件文件大小
        /// </summary>
        public int MaxUploadFileSize { get; set; }
        /// <summary>
        /// 总附件文件大小
        /// </summary>
        public int TotalUploadFileSize { get; set; }
        /// <summary>
        /// 图片文件缩略图前缀
        /// </summary>
        public string ImageThumbnailPrefix { get; set; }
        /// <summary>
        /// 图片文件缩略图尺寸
        /// </summary>
        public int ImageThumbnailSize { get; set; }
    }
}
